package cn.edu.zzu.nlp.utopiar.action;

import java.awt.event.ActionEvent;

import cn.edu.zzu.nlp.readTree.SaveTree;
import cn.edu.zzu.nlp.readTree.TreeParser;
import cn.edu.zzu.nlp.utopiar.editor.EditorTabbedPane;
import cn.edu.zzu.nlp.utopiar.editor.GraphEditor;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;

public class ActionSave extends ActionGraph{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void actionPerformed(ActionEvent e) {
		GraphEditor editor = getEditor(e);
		mxGraphComponent graphComponent = GraphEditor.getGraphComponent();
		mxGraph graph = graphComponent.getGraph();
		String str = null;
		try {
			str = getSaveStr(editor, EditorTabbedPane.getPATH().equalsIgnoreCase(EditorTabbedPane.getEnglishPath())?
					EditorTabbedPane.getZhGraph():EditorTabbedPane.getEngGraph());
			if(str==null){
				return;
			}
			SaveTree.save(TreeParser.getNow(), str ,EditorTabbedPane.getPATH().equalsIgnoreCase(EditorTabbedPane.getEnglishPath())?
					EditorTabbedPane.getChinesePath():EditorTabbedPane.getEnglishPath());
			SaveTree.save(EditorTabbedPane.getPATH().equalsIgnoreCase(EditorTabbedPane.getEnglishPath())?
					EditorTabbedPane.getChinesePath():EditorTabbedPane.getEnglishPath());
			str = getSaveStr(editor, graph);
			if(str==null){
				System.out.print("str="+str);
				return;
			}			
			SaveTree.save(TreeParser.getNow(), str, EditorTabbedPane.getPATH());
			SaveTree.save(EditorTabbedPane.getPATH());
		} catch (Exception e1) {
			e1.printStackTrace();
	    }
	}

}
